<?php


/**
 * This file is part of project alg-performance.
 *
 * Author: Jake
 * Create: 2019-04-30 17:34:39
 */

namespace App\Helper;

trait SingletonAble
{
    private $self;

    /**
     *
     * @return static
     */
    public static function getInstance()
    {
        return self::init();
    }

    /**
     * @param mixed ...$params
     * @return SingletonAble
     */
    public static function init(...$params)
    {
        static $self;

        if ($self instanceof static === false) {
            $self = count($params) ? new static(...$params) : new static;
        }

        return $self;
    }
}
